package cn.tedu.jsd2210.csmall.product.controller;

import cn.tedu.jsd2210.csmall.product.pojo.dto.BrandAddNewDto;
import cn.tedu.jsd2210.csmall.product.pojo.dto.BrandUpdateDto;
import cn.tedu.jsd2210.csmall.product.pojo.dto.PictureAddNewDto;
import cn.tedu.jsd2210.csmall.product.pojo.vo.BrandListItemVO;
import cn.tedu.jsd2210.csmall.product.pojo.vo.BrandStandardVO;
import cn.tedu.jsd2210.csmall.product.service.IBrandService;
import cn.tedu.jsd2210.csmall.product.service.IPictureService;
import cn.tedu.jsd2210.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/pictures")
@Api(tags="07.图片管理模块")
@Validated
public class PictureController {
    @Autowired
    private IPictureService pictureService;
//http://localhost:9080/pictures/add-new
    @ApiOperation("添加图片")
    @PostMapping("/add-new")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid PictureAddNewDto pictureAddNewDto){
            log.debug("开始处理添加品牌的请求,参数:{}",pictureAddNewDto);
        pictureService.addNew(pictureAddNewDto);
            return JsonResult.ok();
    }
    //http://localhost:9080/brands/{?}/delete
    @ApiOperation("根据ID删除图片")
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "图片ID", required = true, dataType = "long")
    })
    public JsonResult<Void> delete(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id){
        log.debug("开始处理添加品牌的请求,参数:{}",id);
        pictureService.delete(id);
        return JsonResult.ok();
    }


}
